package com.btpj.hospital_server.controller;

import com.btpj.hospital_server.dto.CommonPage;
import com.btpj.hospital_server.dto.CommonResult;
import com.btpj.hospital_server.entity.HospitalInfo;
import com.btpj.hospital_server.entity.LogAccountLogin;
import com.btpj.hospital_server.entity.LogOperation;
import com.btpj.hospital_server.service.LogAccountLoginService;
import com.btpj.hospital_server.service.LogOperationService;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "日志接口")
@RestController
@RequestMapping("/log")
public class LogController {

    @Resource
    private LogAccountLoginService logAccountLoginService;

    @Resource
    private LogOperationService logOperationService;

    @ApiOperation("分页查询登录日志信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountName", value = "账号名称(模糊匹配)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "第几页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query")
    })
    @GetMapping("/loginLogListPage")
    public CommonResult<CommonPage<LogAccountLogin>> getLoginLogPageList(@RequestParam(required = false) String accountName,
                                                                         @RequestParam Integer pageNo,
                                                                         @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        CommonPage<LogAccountLogin> commonPage = CommonPage.listPage(logAccountLoginService.getList(accountName));
        return CommonResult.success(commonPage);
    }

    @ApiOperation("分页查询操作日志信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountName", value = "账号名称(模糊匹配)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "method", value = "请求方式（get/post/put/delete...）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "第几页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query")
    })
    @GetMapping("/operationLogListPage")
    public CommonResult<CommonPage<LogOperation>> getLoginLogPageList(@RequestParam(required = false) String accountName,
                                                                      @RequestParam(required = false) String method,
                                                                      @RequestParam Integer pageNo,
                                                                      @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        CommonPage<LogOperation> commonPage = CommonPage.listPage(logOperationService.getList(accountName,method));
        return CommonResult.success(commonPage);
    }

}
